package drds.server.config.loader.xml;

import java.util.Map;

import drds.server.config.cluster.ClusterConfig;
import drds.server.config.loader.Config;
import drds.server.config.loader.SchemaLoader;
import drds.server.config.model.DRDS;
import drds.server.config.model.GroupDataSourceConfig;
import drds.server.config.model.GroupDataSourceNodeConfig;
import drds.server.config.model.Schema;
import drds.server.config.model.User;

/**
 * 
 */
public class XmlConfig implements Config {

	/** unmodifiable */
	private final Map<String, GroupDataSourceConfig> groupDataSourceConfigMap;
	/** unmodifiable */
	private final Map<String, GroupDataSourceNodeConfig> groupDataSourceNodeConfigMap;
	/** unmodifiable */
	private final Map<String, Schema> schemaMap;
	private final DRDS drds;
	/** unmodifiable */
	private final Map<String, User> userMap;
	private final ClusterConfig clusterConfig;

	public XmlConfig(SchemaLoader schemaLoader) {
		ServerLoader serverLoader = new ServerLoader();
		this.drds = serverLoader.getDRDS();
		this.userMap = serverLoader.getUserMap();
		this.clusterConfig = serverLoader.getClusterConfig();
		this.groupDataSourceConfigMap = schemaLoader.getGroupDataSourceConfigMap();
		this.groupDataSourceNodeConfigMap = schemaLoader.getGroupDataSourceNodeConfigMap();
		this.schemaMap = schemaLoader.getSchemaMap();
		schemaLoader = null;
	}

	@Override
	public ClusterConfig getClusterConfig() {
		return clusterConfig;
	}

	@Override
	public User getUser(String user) {
		return userMap.get(user);
	}

	@Override
	public Map<String, User> getUserMap() {
		return userMap;
	}

	@Override
	public DRDS getSystemConfig() {
		return drds;
	}

	@Override
	public Map<String, Schema> getSchemaMap() {
		return schemaMap;
	}

	@Override
	public Map<String, GroupDataSourceNodeConfig> getGroupDataSourceNodeConfigMap() {
		return groupDataSourceNodeConfigMap;
	}

	@Override
	public Map<String, GroupDataSourceConfig> getGroupDataSourceConfigMap() {
		return groupDataSourceConfigMap;
	}

	@Override
	public Schema getSchema(String schema) {
		return schemaMap.get(schema);
	}

}